home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-16 | 4.9 KB | 138 lines | [TEXT/MPS ] |
- #-----------------------------------------------------------------------------------------------------------------------------------------------------
- # A2Hex
- # MPW Shell Script
- #
- # Original by Stuart Davidson
- # Changes by Gina Cherry • August 16, 1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage: A2Hex [file]
- #
- # Function:
- # A2Hex takes one or more lines of assembly language and computes the equivalent in
- # hexadecimal. The assembly lines cannot contain variables, labels, or procedure
- # headers. If an input file is not specified, A2Hex prompts the user for a line of assembly
- # language. If an input file is specified, A2Hex converts the selected text in the input file
- # to hex.
- #
- # Note:
- # A2Hex can be added to the Tools menu with the following command:
- # AddMenu Tools A2Hex 'A2Hex "{Active}" ∑∑ "{Worksheet}"'
- #----------------------------------------------------------------------------------------------------------------------------------------------------
-
-
-
- # The first section of this script consists of commands which are executed by the MPW Shell.
- # These commands are ignored by StreamEdit, because of the semi-colon in the first column.
-
- #----------------------------------------------------------------------------------------------------------------------------------------------------
- # Shell Commands
- #----------------------------------------------------------------------------------------------------------------------------------------------------
-
- ; # If more than one parameter was given, write error message and exit script.
- ; If {#} > 1
- ; Echo "### Usage: {0} [file]" >> Dev:StdErr
- ; Exit 1
- ; End
- ;
- ; # Don't exit on error.
- ; Set Exit 0
- ;
- ; # Write procedure header to temporary file.
- ; Echo 'FOO PROC' > "{0}Temp.a"
- ;
- ; # If an input file was specified:
- ; If {#} == 1
- ; # Copy selected text from input file to clipboard.
- ; Copy § "{1}" ≥ Dev:Null
- ; # Exit if no text is selected in the input file.
- ; If {Status} != 0
- ; Delete {0}Temp.a
- ; Exit 0
- ; End
- ; # Save value of {NewWindowRect}
- ; Set OldWindowRect "{NewWindowRect}"
- ; # Want to open a small workspace.
- ; Set NewWindowRect 0,0,100,100
- ; # Open temporary file.
- ; Open {0}Temp.a
- ; # Restore old value of {NewWindowRect}
- ; Set NewWindowRect "{OldWindowRect}"
- ; # Append text from clipboard to temporary file.
- ; Paste ∞ {0}Temp.a
- ; # Write a newline to temporary file.
- ; Echo >> {0}Temp.a
- ; # Insert tabs.
- ; # Set count to the number of lines in the temporary file.
- ; Set count `Count -l {0}Temp.a`
- ; # Loop through lines.
- ; Loop
- ; # Break if on first line.
- ; Break if {count} == 1
- ; # Position cursor at beginning of current line.
- ; Find Δ{count} {0}Temp.a
- ; # Insert tab at beginning of line.
- ; Replace /(≈)®1/ ∂t®1 {0}Temp.a
- ; # Decrement count.
- ; Set count `evaluate {count} -1`
- ; End
- ;
- ; # Close temporary file
- ; Close -y {0}Temp.a
- ;
- ; # If no input file was specified:
- ; Else
- ; # Request a line of assembly code.
- ; Set assembly "`Request "Assembly to hex:"`"
- ; # If Cancel button was chosen, delete temporary file and exit script.
- ; If "{assembly}" == ""
- ; Delete {0}Temp.a
- ; Exit 0
- ; End
- ; # Write assembly code to temporary file.
- ; Echo -n ∂t >> {0}Temp.a
- ; Echo "{assembly}" >> {0}Temp.a
- ; End
- ;
- ; Echo "∂tRTS" >> {0}Temp.a
- ; Echo "∂tENDPROC" >> {0}Temp.a
- ; Echo "∂tEND" >> {0}Temp.a
- ;
- ; # Assemble temporary file.
- ; Asm {0}Temp.a
- ;
- ; # If assembly fails, exit script.
- ; If {Status} != 0
- ; Echo "### {0}: Assembly failed." >> StdErr
- ; Exit 3
- ; End
- ;
- ; # Pipe output of Dumpobj to StreamEdit command. Dumpobj writes disassembled code to standard
- ; # output. StreamEdit executes the StreamEdit statements at the bottom of this file to extract the
- ; # hex equivalent of the assembly input from the Dumpobj output. The call to StreamEdit uses
- ; # the command Which "{0}", which expands into the name of the currently running shell script.
- ; # The -d option causes StreamEdit to discard text from the input file, writing only the output
- ; # from print statements to standard output.
- ; Dumpobj -m FOO {0}Temp.a.o | StreamEdit -d -s `Which "{0}"`
- ;
- ; # Delete temporary file(s).
- ; Delete {0}Temp≈
- ;
- ; # Exit shell script.
- ; Exit
-
-
-
- #----------------------------------------------------------------------------------------------------------------------------------------------------
- # StreamEdit Statements
- #----------------------------------------------------------------------------------------------------------------------------------------------------
-
- # These statements are meant to operate on the output of the Dumpobj shell command. They write
- # each instruction (except the RTS instruction) in both assembly and hexadecimal to standard
- # output.
-
- # Find all hex lines except the one representing the RTS instruction.
- (!/[0-9]«8»:≈RTS≈/) && (/[0-9]«8»: ([0-9a-fA-F ]+)®1≈∂'≈∂'[ ]+([¬ ∂n]+≈)®2/)
- # Print hex and assembly equivalent to output file.
- print ®1'#'®2
-